home *** CD-ROM | disk | FTP | other *** search
/ Programming Windows 95 with MFC / Programming Windows 95 with MFC (Microsoft Programming Series)(097-0001465)(1996).iso / CODE / Chap08 / Paint4 / AboutDlg.cpp next >
Encoding:
C/C++ Source or Header  |  1996-04-05  |  1.3 KB  |  51 lines

  1. //***********************************************************************
  2. //
  3. //  AboutDlg.cpp
  4. //
  5. //***********************************************************************
  6.  
  7. #include <afxwin.h>
  8. #include "Resource.h"
  9. #include "AboutDlg.h"
  10.  
  11. BEGIN_MESSAGE_MAP (CAboutDialog, CDialog)
  12.     ON_WM_PAINT ()
  13. END_MESSAGE_MAP ()
  14.  
  15. BOOL CAboutDialog::OnInitDialog ()
  16. {
  17.     CDialog::OnInitDialog ();
  18.  
  19.     CStatic* pStatic = (CStatic*) GetDlgItem (IDC_ICONRECT);
  20.     pStatic->GetWindowRect (&m_rect);
  21.     pStatic->DestroyWindow ();
  22.     ScreenToClient (&m_rect);
  23.  
  24.     return TRUE;
  25. }
  26.  
  27. void CAboutDialog::OnPaint ()
  28. {
  29.     CPaintDC dc (this);
  30.     HICON hIcon = (HICON) ::GetClassLong (AfxGetMainWnd ()->m_hWnd,
  31.         GCL_HICON);
  32.  
  33.     if (hIcon != NULL) {
  34.         CDC dcMem;
  35.         dcMem.CreateCompatibleDC (&dc);
  36.  
  37.         CBitmap bitmap;
  38.         bitmap.CreateCompatibleBitmap (&dc, 32, 32);
  39.         CBitmap* pOldBitmap = dcMem.SelectObject (&bitmap);
  40.  
  41.         CBrush brush (::GetSysColor (COLOR_3DFACE));
  42.         dcMem.FillRect (CRect (0, 0, 32, 32), &brush);
  43.         dcMem.DrawIcon (0, 0, hIcon);
  44.  
  45.         dc.StretchBlt (m_rect.left, m_rect.top, m_rect.Width(),
  46.             m_rect.Height (), &dcMem, 0, 0, 32, 32, SRCCOPY);
  47.  
  48.         dcMem.SelectObject (pOldBitmap);
  49.     }
  50. }
  51.